var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/configComponent/tabPanel/index.tsx
var tabPanel_exports = {};
__export(tabPanel_exports, {
  default: () => tabPanel_default
});
module.exports = __toCommonJS(tabPanel_exports);
var import_react = require("react");
var import_functionalComponent = require("../../functionalComponent");
var import_util = require("../../util");
var import_common = require("../common");
var import_baseConfig = require("../config/baseConfig");
var import_index = require("./index.less");
function TabPanelComp(props) {
  const { formConf, outRef, type = "line", forceRender, panelHeight, ...others } = props;
  const [panes, setPanes] = (0, import_react.useState)(() => []);
  const [activeKey, setActiveKey] = (0, import_util.useRefValue)(props.activeKey, props.defaultActiveKey);
  (0, import_react.useEffect)(() => {
    var _a;
    const p = (Array.isArray(formConf) ? formConf : formConf.children || []).map((item) => {
      item["key"] = item.id;
      return item;
    });
    setPanes(p);
    p.every(({ key }) => key !== activeKey) && setActiveKey((_a = p[0]) == null ? void 0 : _a.key);
  }, [formConf]);
  const onInnerChange = (0, import_util.useRefCallback)((key) => {
    var _a;
    setActiveKey(key);
    (_a = props.onChange) == null ? void 0 : _a.call(props, key);
  });
  const getItems = () => {
    const childArray = import_util.iup.flatArray(props.children || []);
    const t = childArray.reduce((acc, it) => {
      const tabId = it.props && it.props["data-tabid"] || it.key;
      tabId && (acc[tabId] = it);
      return acc;
    }, {});
    const getChildItem = (item) => {
      if (t[item.id]) {
        return t[item.id];
      } else {
        const Comp = (import_baseConfig.Comp_Info[item.xtype] || {
          instance: (0, import_util.getRegisterComponentWithProps)(item.xtype)[0] || item.xtype
        }).instance;
        if (import_baseConfig.Comp_Info[item.xtype])
          return /* @__PURE__ */ React.createElement(Comp, { config: item });
        return import_util.iup.isFunction(Comp) ? /* @__PURE__ */ React.createElement(Comp, { config: item }) : Comp;
      }
    };
    return panes.filter((p) => !p.hidden).map((pane) => {
      var _a;
      const contentItemProps = ((_a = t[pane.id]) == null ? void 0 : _a.props) || {};
      return {
        label: pane.title,
        key: pane.id,
        forceRender: contentItemProps["data-forceRender"] || pane.forceRender || forceRender,
        children: /* @__PURE__ */ React.createElement("div", { style: { minHeight: contentItemProps.panelHeight || pane.height || panelHeight } }, getChildItem(pane))
      };
    });
  };
  return /* @__PURE__ */ React.createElement(
    import_functionalComponent.Tabs,
    {
      ...others,
      type,
      ref: outRef,
      fitHeight: true,
      size: "small",
      onChange: onInnerChange,
      activeKey: activeKey + "",
      style: props.style,
      className: import_util.iup.classNames("iup-tab-panel", props.className),
      items: getItems()
    }
  );
}
var TabPanel = (0, import_util.compHoc)((0, import_common.LayConfWrap)(TabPanelComp));
var tabPanel_default = TabPanel;
(0, import_util.registerComponent)({ TabPanel });
